using System;
using System.Collections;
using System.Windows.Forms;
namespace NoteManger
{
	public class ListViewColumnSorter : IComparer
	{
		private int ColumnToSort;
		private SortOrder OrderOfSort;
		private CaseInsensitiveComparer ObjectCompare;
		public int SortColumn
		{
			get
			{
				return this.ColumnToSort;
			}
			set
			{
				this.ColumnToSort = value;
			}
		}
		public SortOrder Order
		{
			get
			{
				return this.OrderOfSort;
			}
			set
			{
				this.OrderOfSort = value;
			}
		}
		public ListViewColumnSorter()
		{
			this.ColumnToSort = 0;
			this.OrderOfSort = SortOrder.None;
			this.ObjectCompare = new CaseInsensitiveComparer();
		}
		public int Compare(object x, object y)
		{
			ListViewItem listViewItem = (ListViewItem)x;
			ListViewItem listViewItem2 = (ListViewItem)y;
			int num;
			int result;
			try
			{
				num = this.ObjectCompare.Compare(listViewItem.SubItems[this.ColumnToSort].Text, listViewItem2.SubItems[this.ColumnToSort].Text);
			}
			catch
			{
				result = 0;
				return result;
			}
			if (this.OrderOfSort == SortOrder.Ascending)
			{
				result = num;
			}
			else
			{
				if (this.OrderOfSort == SortOrder.Descending)
				{
					result = -num;
				}
				else
				{
					result = 0;
				}
			}
			return result;
		}
	}
}
